import { SubjectType } from '@/apis';
import { getAreaConfig, getIndustryConfig, getTagTypeConfig } from '@/utils/filterConfig';
import type { IBeforeApply } from '../apis';

const option = [
  { name: '全部', code: '' },
  { name: '是', code: '1' },
  { name: '否', code: '0' }
];

const moreData = [
  {
    name: '是否投产',
    code: 'productionOrNot',
    data: option
  },
  {
    name: '所在地是否属于大气重点控制区',
    code: 'keyAtmosphericControlArea',
    data: option
  },
  {
    name: '所在地是否属于总磷控制区',
    code: 'totalPhosphorusControlArea',
    data: option
  },
  {
    name: '所在地是否属于总氮控制区',
    code: 'totalNitrogenControlArea',
    data: option
  },
  {
    name: '所在地是否属于重金属污染特别排放限值实施区域',
    code: 'heavyMetalPollutionLimitArea',
    data: option
  },
  {
    name: '是否属于工业园区',
    code: 'locatedInIndustrialPark',
    data: option
  }
];

export function useScreen( ) {
  const PAGE_SIZE = 15;

  const queryData = reactive<IBeforeApply>({
    pageNum: 1,
    pageSize: PAGE_SIZE,
    searchTxt: '',
    sortRule: '',
    provinceCode: '',
    cityCode: '',
    countryCode: '',
    industryCategoryCodeLv1: '',
    industryCategoryCodeLv2: '',
    industryCategoryCodeLv3: '',
    tagTypeCode: ''
  });

  // 地区 
  const areaData = getAreaConfig();
  areaData.value.submitFn = (val) => {
    const { lv1, lv2, lv3 } = val;
    
    queryData.provinceCode = lv1.join();
    queryData.cityCode = lv2.join();
    queryData.countryCode = lv3.join();
  };

  // 行业
  const industryData = getIndustryConfig();
  industryData.value.submitFn = (val) => {
    const { lv1, lv2, lv3 } = val;
    
    queryData.industryCategoryCodeLv1 = lv1?.join() || '';
    queryData.industryCategoryCodeLv2 = lv2?.join() || '';
    queryData.industryCategoryCodeLv3 = lv3?.join() || '';
  };

  // 企业类型
  const tagTypeData = getTagTypeConfig(SubjectType.PERMIT);
  tagTypeData.value.submitFn = (data) => {
    queryData.tagTypeCode = data;
  };

  // 更多
  const moreFilter = ref({
    title: '更多',
    component: 'tiled-select',
    options: moreData,
    submitFn: (data) => {
      Object.assign(queryData, data);
    }
  });

  const screen = ref([areaData.value, industryData.value, tagTypeData.value, moreFilter.value]);

  return {
    PAGE_SIZE,
    screen,
    queryData
  };
}
